﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SuperQuery.UserControls.ToolBars
{
    /// <summary>
    /// Interaction logic for DatabaseListToolBar.xaml
    /// </summary>
    public partial class DatabaseListToolBar : ToolBarBase
    {
        /// <summary>
        /// DatabaseList Tool bar constructor
        /// </summary>
        public DatabaseListToolBar()
        {
            InitializeComponent();

            // Set intial state of toolbar buttons
            EnabledChanged(null, null);
        }

        /// <summary>
        /// Event raised when the enabled property is changed
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        protected override void EnabledChanged(object sender, EventArgs e)
        {
            bool isEnabled = Enabled;
            btnAddDatabases.IsEnabled = isEnabled;
            btnRemoveDatabases.IsEnabled = isEnabled;
            mnuSelect.IsEnabled = isEnabled;
        }

        /// <summary>
        /// Raise an event to signal that the user wants to add databases
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void btnAddDatabases_Click(object sender, RoutedEventArgs e)
        {
            OnToolBarOperation(ToolBarButtons.AddDatabase);
        }

        /// <summary>
        /// Raise an event to signal that the user wants to remove databases
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void btnRemoveDatabases_Click(object sender, RoutedEventArgs e)
        {
            OnToolBarOperation(ToolBarButtons.RemoveDataBase);
        }

        /// <summary>
        /// Raise an event to signal that the user wants to select any database that failed to run the last query
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void mnuSelectFailures_Click(object sender, RoutedEventArgs e)
        {
            OnToolBarOperation(ToolBarButtons.SelectFailures);
        }

        /// <summary>
        /// Raise an event to signal that the user wants to select any database that successfully ran the last query
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void mnuSelectSuccesses_Click(object sender, RoutedEventArgs e)
        {
            OnToolBarOperation(ToolBarButtons.SelectSuccesses);
        }

        /// <summary>
        /// Raise an event to signal that the user wants to select all databases
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void mnuSelectAll_Click(object sender, RoutedEventArgs e)
        {
            OnToolBarOperation(ToolBarButtons.SelectAll);
        }

        /// <summary>
        /// Raise an event to signal that the user wants to invert their current database selection
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void mnuSelectInvert_Click(object sender, RoutedEventArgs e)
        {
            OnToolBarOperation(ToolBarButtons.InvertSelection);
        }
    }
}
